<?
$path = "../upload";
$pathdb = "../upload";
if (isset($_POST['butSaveLoai'])) {
	$image = $_POST['txtImage'];
	$parent = $_POST['txtParent'];
	$sort = (int)$_POST['txtSortOrder'];
	$status=($_POST['chkShow']!=''?1:0);
	$notsub=($_POST['chknotsub']!=''?1:0);
	$language=$_POST['ddlLanguage'];
	$ret=CheckUpload($_FILES["txtImage"],".jpg;.swf;.jpeg;.gif;.png;",500*1024,($_POST['id']!=''?0:1));
	//if ($ret) $err.="T&#7853;p tin không &#273;úng &#273;&#7883;nh d&#7841;ng ho&#7863;c kích th&#432;&#7899;c quá l&#7899;n<br>";			
	$ten = trim($_POST['txtName']);
	if ($ten=="")
	{
		echo "<p align=center class='err'>B&#7841;n ch&#432;a nh&#7853;p tên danh m&#7909;c</p>";
	}
	else
	{
		if (!empty($_POST['oldid'])) {
			$oldid = $_POST['oldid'];
			$sql = "update newscategoriesvn set categories_name='".$ten."', parent_id='".$parent."', sort_order='".$sort."',categories_notsub=".$notsub.", status=".$status." where categories_id='".$oldid."'";
		}
		else 
			$sql = "insert into newscategoriesvn (categories_name,parent_id,sort_order,categories_notsub, status) values ('".$ten."','".$parent."','".$sort."',".$notsub.",".$status.")";
		/*if (mysql_query($sql,$con)) {
			echo "<p align=center class='err'>&#272;ã c&#7853;p nh&#7853;t thành công</p><br>";
			echo "<script>window.location='index.php?act=new_danhmucvn&cat=".$_REQUEST['cat']."&page=".$_REQUEST['page']."'</script>";
		}
		else echo "<p align=center class='err'>Không th&#7875; c&#7853;p nh&#7853;t</p>";*/
		
				if (mysql_query($sql,$con)) {
			if(empty($_POST['oldid'])) $oldid = mysql_insert_id();

			$sqlUpdateField = "";
			$ext=GetFileExtention($_FILES['txtImage']['name']);
			if (MakeUpload($_FILES['txtImage'],"$path/categories_c$oldid$ext"))
			{
				@chmod("$path/categories_c$oldid$ext", 0777);
				$sqlUpdateField = "categories_description='$pathdb/categories_c$oldid$ext' ";
			}
			
			// update image
			if($sqlUpdateField)
			{
				$sqlUpdate = "update newscategoriesvn set $sqlUpdateField where categories_id='".$oldid."'";
				mysql_query($sqlUpdate,$con);
			}
			echo "<p align=center class='err'>&#272;ã c&#7853;p nh&#7853;t thành công</p><br>";
			echo "<script>window.location='index.php?act=new_danhmucvn&cat=".$_REQUEST['cat']."&page=".$_REQUEST['page']."'</script>";
		}	
		else {
			$err =  "<p align=center class='err'>Không th&#7875; c&#7853;p nh&#7853;t</p>";
		}
		
	}
} 
?>

<?
	if (isset($_GET['id'])) {
		$oldid=$_GET['id'];
		$sql = "select * from newscategoriesvn where categories_id='".$oldid."'";
		if ($result = mysql_query($sql,$con)) {
			$row=mysql_fetch_array($result);
			$CategoryName=$row['categories_name'];
			$notsub=$row['categories_notsub'];
			$parent=$row['parent_id'];
			$order=$row['sort_order'];
			$status=$row['categories_status'];
			
		
		
		}
	}
?>

<form method="POST" name="FormLoaiSP"  enctype="multipart/form-data" action="index.php">
<input type=hidden name="act" value="new_danhmucvn_m">
<input type=hidden name="oldid" value="<? echo $oldid; ?>">
<input type=hidden name="page" value="<? echo $_REQUEST['page']; ?>">
<input type=hidden name="cat" value="<? echo $_REQUEST['cat']; ?>">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#0069A8" width="100%" id="AutoNumber1">
  <tr>
    <td width="45%" align="center" class="title" height="20">S&#7917;a &#273;&#7893;i / C&#7853;p nh&#7853;t : Danh m&#7909;c Tin T&#7913;c </td>
  </tr>
  <tr>
    <td width="45%">
    <table border="0" cellpadding="4" bordercolor="#111111" width="124%" id="AutoNumber2" cellspacing="0">
<? if (GetConfig('multilanguage')==1)
{
?>
	  
<?
}
?>
      <tr>
        <td width="18%" class="smallfont">
        <p align="right">Tên danh m&#7909;c</td>
        <td width="1%" class="smallfont">
        <font color="#FF0000">*</font></td>
        <td width="83%" class="smallfont">
		<INPUT value="<? echo $CategoryName; ?>" TYPE="text" NAME="txtName" CLASS=textbox size="34"></td>
      </tr>
   <!--   
           <tr>
        <td width="18%" class="smallfont">
        <p align="right">Icon flash </td>
        <td width="1%" class="smallfont" align="center">
        <font color="#FF0000">*</font></td>
        <td width="83%" class="smallfont">
	<INPUT TYPE="file" NAME="txtImage" CLASS=textbox size="34"></td>
      </tr>
      -->
      <tr>
        <td width="18%" class="smallfont" align="right">
        Không hi&#7875;n th&#7883;</td>
        <td width="1%" class="smallfont" align="right">&nbsp;        </td>
        <td width="83%" class="smallfont">
		<input type="checkbox" name="chkShow" value="ON" <? if ($status>0) echo 'checked' ?>></td>
      </tr>
 <!--     <tr>
        <td width="18%" class="smallfont" align="right">
        Không có danh m&#7909;c con</td>
        <td width="1%" class="smallfont" align="right">&nbsp;        </td>
        <td width="83%" class="smallfont">
		<input name="chknotsub" type="checkbox" value="ON" checked="checked" <? if ($notsub>0) echo 'checked' ?>></td>
      </tr>   -->    
      <tr>
        <td width="18%" class="smallfont" align="right">
        Th&#7913; t&#7921; s&#7855;p x&#7871;p</td>
        <td width="1%" class="smallfont" align="right">&nbsp;        </td>
        <td width="83%" class="smallfont">
		<INPUT value="<? echo $order; ?>" TYPE="text" NAME="txtSortOrder" CLASS=textbox size="34"></td>
      </tr>
      <tr>
        <td width="18%" class="smallfont">
		<p align="right"><INPUT TYPE="submit" NAME="butSaveLoai" VALUE=" L&#432;u " CLASS=button>&nbsp;</td>
        <td width="1%" class="smallfont">&nbsp;		</td>
        <td width="83%" class="smallfont"><p align="left">&nbsp;<INPUT TYPE="reset" CLASS=button></td>
      </tr>
    </table>
    </td>
  </tr>
  </table>
</form>
